package com.framework.web.bus.service;

import com.framework.web.bus.domain.Thumb;
import com.framework.web.bus.repository.ThumbRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author fusf
 * @version V1.0
 * @Title: Service
 * @Description: 业务层
 * @date 2016-09-11
 */
@Service
public class ThumbService {

    @Autowired
    private ThumbRepository thumbRepository;

    /**
     * 新增或者保存
     *
     * @param thumb
     * @return
     */
    public Thumb save(Thumb thumb) {
        return thumbRepository.save(thumb);
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    public Thumb findById(String id) {
        return thumbRepository.findOne(id);
    }

    /**
     * 根据用户和菜谱ID获取列表
     *
     * @param userId
     * @param cookbookId
     * @return
     */
    public Thumb findByUserIdAndCookbookId(String userId, String cookbookId) {
        List<Thumb> thumbList = thumbRepository.findByUserIdAndCookbookId(userId, cookbookId);
        if (thumbList != null && thumbList.size() > 0) {
            return thumbList.get(0);
        }
        return null;
    }

}
